
#pragma once

class CEqualizerDlg : public CDialogImpl<CEqualizerDlg>, public CWinDataExchange<CEqualizerDlg>
{
private:
	TCHAR str[20];
	CTrackBarCtrl sliderGain0;
	CTrackBarCtrl sliderGain1;
	CTrackBarCtrl sliderGain2;
	CTrackBarCtrl sliderGain3;
	CTrackBarCtrl sliderFreq0;
	CTrackBarCtrl sliderFreq1;
	CTrackBarCtrl sliderFreq2;
	CTrackBarCtrl sliderFreq3;
	CTrackBarCtrl sliderBand0;
	CTrackBarCtrl sliderBand1;
	CTrackBarCtrl sliderBand2;
	CTrackBarCtrl sliderBand3;

	FXEQ_PARAMETERS &Parameters;
	FXEQ_PARAMETERS CurrentParameters;
public:
	enum { IDD = IDD_EQUALIZER };

	CEqualizerDlg(FXEQ_PARAMETERS& Param) : Parameters(Param) {} ;

	BEGIN_MSG_MAP(CEqualizerDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_ID_HANDLER(IDOK, OnOkCloseCmd)
		COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
		
		NOTIFY_HANDLER(IDC_SLIDER_GAIN0, NM_CUSTOMDRAW, OnNMCustomDrawSliderGain0)
		NOTIFY_HANDLER(IDC_SLIDER_GAIN1, NM_CUSTOMDRAW, OnNMCustomDrawSliderGain1)
		NOTIFY_HANDLER(IDC_SLIDER_GAIN2, NM_CUSTOMDRAW, OnNMCustomDrawSliderGain2)
		NOTIFY_HANDLER(IDC_SLIDER_GAIN3, NM_CUSTOMDRAW, OnNMCustomDrawSliderGain3)
		NOTIFY_HANDLER(IDC_SLIDER_FREQ0, NM_CUSTOMDRAW, OnNMCustomDrawSliderFreq0)
		NOTIFY_HANDLER(IDC_SLIDER_FREQ1, NM_CUSTOMDRAW, OnNMCustomDrawSliderFreq1)
		NOTIFY_HANDLER(IDC_SLIDER_FREQ2, NM_CUSTOMDRAW, OnNMCustomDrawSliderFreq2)
		NOTIFY_HANDLER(IDC_SLIDER_FREQ3, NM_CUSTOMDRAW, OnNMCustomDrawSliderFreq3)
		NOTIFY_HANDLER(IDC_SLIDER_BAND0, NM_CUSTOMDRAW, OnNMCustomDrawSliderBand0)
		NOTIFY_HANDLER(IDC_SLIDER_BAND1, NM_CUSTOMDRAW, OnNMCustomDrawSliderBand1)
		NOTIFY_HANDLER(IDC_SLIDER_BAND2, NM_CUSTOMDRAW, OnNMCustomDrawSliderBand2)
		NOTIFY_HANDLER(IDC_SLIDER_BAND3, NM_CUSTOMDRAW, OnNMCustomDrawSliderBand3)
	END_MSG_MAP()

		BEGIN_DDX_MAP()
		DDX_TEXT(IDC_EDIT_GAIN0, str)
		DDX_TEXT(IDC_EDIT_GAIN1, str)
		DDX_TEXT(IDC_EDIT_GAIN2, str)
		DDX_TEXT(IDC_EDIT_GAIN3, str)
		DDX_TEXT(IDC_EDIT_FREQ0, str)
		DDX_TEXT(IDC_EDIT_FREQ1, str)
		DDX_TEXT(IDC_EDIT_FREQ2, str)
		DDX_TEXT(IDC_EDIT_FREQ3, str)
		DDX_TEXT(IDC_EDIT_BAND0, str)
		DDX_TEXT(IDC_EDIT_BAND1, str)
		DDX_TEXT(IDC_EDIT_BAND2, str)
		DDX_TEXT(IDC_EDIT_BAND3, str)

	END_DDX_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CenterWindow(GetParent());

		sliderGain0.Attach(GetDlgItem(IDC_SLIDER_GAIN0));
		sliderGain0.SetRange((int)1000 * FXEQ_MIN_GAIN, (int)1000 * FXEQ_MAX_GAIN,  true);
		//sliderGain0.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
		if (Parameters.Gain0 >= FXEQ_MIN_GAIN && Parameters.Gain0 <= FXEQ_MAX_GAIN){
			sliderGain0.SetPos((int)1000 * (Parameters.Gain0));
			CurrentParameters.Gain0 = Parameters.Gain0;
		} else {
			sliderGain0.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
			CurrentParameters.Gain0 = FXEQ_DEFAULT_GAIN;
		}

		sliderGain1.Attach(GetDlgItem(IDC_SLIDER_GAIN1));
		sliderGain1.SetRange((int)1000 * FXEQ_MIN_GAIN, (int)1000 * FXEQ_MAX_GAIN,  true);
		//sliderGain1.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
		if (Parameters.Gain1 >= FXEQ_MIN_GAIN && Parameters.Gain1 <= FXEQ_MAX_GAIN){
			sliderGain1.SetPos((int)1000 * (Parameters.Gain1));
			CurrentParameters.Gain1 = Parameters.Gain1;
		} else {
			sliderGain1.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
			CurrentParameters.Gain1 = FXEQ_DEFAULT_GAIN;
		}

		sliderGain2.Attach(GetDlgItem(IDC_SLIDER_GAIN2));
		sliderGain2.SetRange((int)1000 * FXEQ_MIN_GAIN, (int)1000 * FXEQ_MAX_GAIN,  true);
		//sliderGain2.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
		if (Parameters.Gain2 >= FXEQ_MIN_GAIN && Parameters.Gain2 <= FXEQ_MAX_GAIN){
			sliderGain2.SetPos((int)1000 * (Parameters.Gain2));
			CurrentParameters.Gain2 = Parameters.Gain2;
		} else {
			sliderGain2.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
			CurrentParameters.Gain2 = FXEQ_DEFAULT_GAIN;
		}

		sliderGain3.Attach(GetDlgItem(IDC_SLIDER_GAIN3));
		sliderGain3.SetRange((int)1000 * FXEQ_MIN_GAIN, (int)1000 * FXEQ_MAX_GAIN,  true);
		//sliderGain3.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
		if (Parameters.Gain3 >= FXEQ_MIN_GAIN && Parameters.Gain3 <= FXEQ_MAX_GAIN){
			sliderGain3.SetPos((int)1000 * (Parameters.Gain3));
			CurrentParameters.Gain3 = Parameters.Gain3;
		} else {
			sliderGain3.SetPos((int)1000 * FXEQ_DEFAULT_GAIN);
			CurrentParameters.Gain3 = FXEQ_DEFAULT_GAIN;
		}

		sliderFreq0.Attach(GetDlgItem(IDC_SLIDER_FREQ0));
		sliderFreq0.SetRange((int)FXEQ_MIN_FREQUENCY_CENTER, (int)FXEQ_MAX_FREQUENCY_CENTER,  true);
		//sliderFreq0.SetPos((int)FXEQ_DEFAULT_FREQUENCY_CENTER_0);
		if (Parameters.FrequencyCenter0 >= FXEQ_MIN_FREQUENCY_CENTER && Parameters.FrequencyCenter0 <= FXEQ_MAX_FREQUENCY_CENTER){
			sliderFreq0.SetPos((int)(Parameters.FrequencyCenter0));
			CurrentParameters.FrequencyCenter0 = Parameters.FrequencyCenter0;
		} else {
			sliderFreq0.SetPos((int) FXEQ_DEFAULT_FREQUENCY_CENTER_0);
			CurrentParameters.FrequencyCenter0 = FXEQ_DEFAULT_FREQUENCY_CENTER_0;
		}

		sliderFreq1.Attach(GetDlgItem(IDC_SLIDER_FREQ1));
		sliderFreq1.SetRange((int)FXEQ_MIN_FREQUENCY_CENTER, (int)FXEQ_MAX_FREQUENCY_CENTER,  true);
		//sliderFreq1.SetPos((int)FXEQ_DEFAULT_FREQUENCY_CENTER_1);
		if (Parameters.FrequencyCenter1 >= FXEQ_MIN_FREQUENCY_CENTER && Parameters.FrequencyCenter1 <= FXEQ_MAX_FREQUENCY_CENTER){
			sliderFreq1.SetPos((int)(Parameters.FrequencyCenter1));
			CurrentParameters.FrequencyCenter1 = Parameters.FrequencyCenter1;
		} else {
			sliderFreq1.SetPos((int) FXEQ_DEFAULT_FREQUENCY_CENTER_1);
			CurrentParameters.FrequencyCenter1 = FXEQ_DEFAULT_FREQUENCY_CENTER_1;
		}

		sliderFreq2.Attach(GetDlgItem(IDC_SLIDER_FREQ2));
		sliderFreq2.SetRange((int)FXEQ_MIN_FREQUENCY_CENTER, (int)FXEQ_MAX_FREQUENCY_CENTER,  true);
		//sliderFreq2.SetPos((int)FXEQ_DEFAULT_FREQUENCY_CENTER_2);
		if (Parameters.FrequencyCenter2 >= FXEQ_MIN_FREQUENCY_CENTER && Parameters.FrequencyCenter2 <= FXEQ_MAX_FREQUENCY_CENTER){
			sliderFreq2.SetPos((int)(Parameters.FrequencyCenter2));
			CurrentParameters.FrequencyCenter2 = Parameters.FrequencyCenter2;
		} else {
			sliderFreq2.SetPos((int) FXEQ_DEFAULT_FREQUENCY_CENTER_2);
			CurrentParameters.FrequencyCenter2 = FXEQ_DEFAULT_FREQUENCY_CENTER_2;
		}

		sliderFreq3.Attach(GetDlgItem(IDC_SLIDER_FREQ3));
		sliderFreq3.SetRange((int)FXEQ_MIN_FREQUENCY_CENTER, (int)FXEQ_MAX_FREQUENCY_CENTER,  true);
		//sliderFreq3.SetPos((int)FXEQ_DEFAULT_FREQUENCY_CENTER_3);
		if (Parameters.FrequencyCenter3 >= FXEQ_MIN_FREQUENCY_CENTER && Parameters.FrequencyCenter3 <= FXEQ_MAX_FREQUENCY_CENTER){
			sliderFreq3.SetPos((int)(Parameters.FrequencyCenter3));
			CurrentParameters.FrequencyCenter3 = Parameters.FrequencyCenter3;
		} else {
			sliderFreq3.SetPos((int) FXEQ_DEFAULT_FREQUENCY_CENTER_3);
			CurrentParameters.FrequencyCenter3 = FXEQ_DEFAULT_FREQUENCY_CENTER_3;
		}

		sliderBand0.Attach(GetDlgItem(IDC_SLIDER_BAND0));
		sliderBand0.SetRange((int)100 * FXEQ_MIN_BANDWIDTH, (int)100 * FXEQ_MAX_BANDWIDTH,  true);
		//sliderBand0.SetPos((int)100 * FXEQ_DEFAULT_BANDWIDTH);
		if (Parameters.Bandwidth0 >= FXEQ_MIN_BANDWIDTH && Parameters.Bandwidth0 <= FXEQ_MAX_BANDWIDTH){
			sliderBand0.SetPos((int)100 * (Parameters.Bandwidth0));
			CurrentParameters.Bandwidth0 = Parameters.Bandwidth0;
		} else {
			sliderBand0.SetPos((int) 100 * FXEQ_DEFAULT_BANDWIDTH);
			CurrentParameters.Bandwidth0 = FXEQ_DEFAULT_BANDWIDTH;
		}

		sliderBand1.Attach(GetDlgItem(IDC_SLIDER_BAND1));
		sliderBand1.SetRange((int)100 * FXEQ_MIN_BANDWIDTH, (int)100 * FXEQ_MAX_BANDWIDTH,  true);
		//sliderBand1.SetPos((int)100 * FXEQ_DEFAULT_BANDWIDTH);
		if (Parameters.Bandwidth1 >= FXEQ_MIN_BANDWIDTH && Parameters.Bandwidth1 <= FXEQ_MAX_BANDWIDTH){
			sliderBand1.SetPos((int)100 * (Parameters.Bandwidth1));
			CurrentParameters.Bandwidth1 = Parameters.Bandwidth1;
		} else {
			sliderBand1.SetPos((int) 100 * FXEQ_DEFAULT_BANDWIDTH);
			CurrentParameters.Bandwidth1 = FXEQ_DEFAULT_BANDWIDTH;
		}

		sliderBand2.Attach(GetDlgItem(IDC_SLIDER_BAND2));
		sliderBand2.SetRange((int)100 * FXEQ_MIN_BANDWIDTH, (int)100 * FXEQ_MAX_BANDWIDTH,  true);
		sliderBand2.SetPos((int)100 * FXEQ_DEFAULT_BANDWIDTH);
		if (Parameters.Bandwidth2 >= FXEQ_MIN_BANDWIDTH && Parameters.Bandwidth2 <= FXEQ_MAX_BANDWIDTH){
			sliderBand2.SetPos((int)100 * (Parameters.Bandwidth2));
			CurrentParameters.Bandwidth2 = Parameters.Bandwidth2;
		} else {
			sliderBand2.SetPos((int) 100 * FXEQ_DEFAULT_BANDWIDTH);
			CurrentParameters.Bandwidth2 = FXEQ_DEFAULT_BANDWIDTH;
		}

		sliderBand3.Attach(GetDlgItem(IDC_SLIDER_BAND3));
		sliderBand3.SetRange((int)100 * FXEQ_MIN_BANDWIDTH, (int)100 * FXEQ_MAX_BANDWIDTH,  true);
		sliderBand3.SetPos((int)100 * FXEQ_DEFAULT_BANDWIDTH);
		if (Parameters.Bandwidth3 >= FXEQ_MIN_BANDWIDTH && Parameters.Bandwidth3 <= FXEQ_MAX_BANDWIDTH){
			sliderBand3.SetPos((int)100 * (Parameters.Bandwidth3));
			CurrentParameters.Bandwidth3 = Parameters.Bandwidth3;
		} else {
			sliderBand3.SetPos((int) 100 * FXEQ_DEFAULT_BANDWIDTH);
			CurrentParameters.Bandwidth3 = FXEQ_DEFAULT_BANDWIDTH;
		}


		return TRUE;
	}

	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		EndDialog(wID);
		return 0;
	}

	LRESULT OnOkCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		Parameters = CurrentParameters;
		EndDialog(wID);
		return 0;
	}

	

	LRESULT OnNMCustomDrawSliderGain0(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderGain0.GetPos();
		swprintf(str, L"%.3f", (float)nVal/1000);
		DoDataExchange(DDX_LOAD, IDC_EDIT_GAIN0);
		CurrentParameters.Gain0 = (float)nVal/1000;
		return 0;
	}


	LRESULT OnNMCustomDrawSliderGain1(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderGain1.GetPos();
		swprintf(str, L"%.3f", (float)nVal/1000);
		DoDataExchange(DDX_LOAD, IDC_EDIT_GAIN1);
		CurrentParameters.Gain1 = (float)nVal/1000;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderGain2(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderGain2.GetPos();
		swprintf(str, L"%.3f", (float)nVal/1000);
		DoDataExchange(DDX_LOAD, IDC_EDIT_GAIN2);
		CurrentParameters.Gain2 = (float)nVal/1000;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderGain3(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderGain3.GetPos();
		swprintf(str, L"%.3f", (float)nVal/1000);
		DoDataExchange(DDX_LOAD, IDC_EDIT_GAIN3);
		CurrentParameters.Gain3 = (float)nVal/1000;
		return 0;
	}

	
	LRESULT OnNMCustomDrawSliderFreq0(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderFreq0.GetPos();
		swprintf(str, L"%.f", (float)nVal);
		DoDataExchange(DDX_LOAD, IDC_EDIT_FREQ0);
		CurrentParameters.FrequencyCenter0 = (float) nVal;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderFreq1(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderFreq1.GetPos();
		swprintf(str, L"%.f", (float)nVal);
		DoDataExchange(DDX_LOAD, IDC_EDIT_FREQ1);
		CurrentParameters.FrequencyCenter1 = (float) nVal;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderFreq2(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderFreq2.GetPos();
		swprintf(str, L"%.f", (float)nVal);
		DoDataExchange(DDX_LOAD, IDC_EDIT_FREQ2);
		CurrentParameters.FrequencyCenter2 = (float) nVal;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderFreq3(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderFreq3.GetPos();
		swprintf(str, L"%.f", (float)nVal);
		DoDataExchange(DDX_LOAD, IDC_EDIT_FREQ3);
		CurrentParameters.FrequencyCenter3 = (float) nVal;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderBand0(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderBand0.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_BAND0);
		CurrentParameters.Bandwidth0 = (float) nVal/100;
		return 0;
	}

	LRESULT OnNMCustomDrawSliderBand1(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderBand1.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_BAND1);
		CurrentParameters.Bandwidth1 = (float) nVal/100;
		return 0;
	}

		LRESULT OnNMCustomDrawSliderBand2(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderBand2.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_BAND2);
		CurrentParameters.Bandwidth2 = (float) nVal/100;
		return 0;
	}

		LRESULT OnNMCustomDrawSliderBand3(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/)
	{		
		int nVal = sliderBand3.GetPos();
		swprintf(str, L"%.2f", (float)nVal/100);
		DoDataExchange(DDX_LOAD, IDC_EDIT_BAND3);
		CurrentParameters.Bandwidth3 = (float) nVal/100;
		return 0;
	}



};
